////////////////////////////////////////////////////////////////////////
// a3.cpp
//
// Third assignment for Advanced Multimedia Computing
//
// T. Kostelijk & F. Huizinga
//     0418889      0418862
//
////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char **argv) {
	// load image 
    IplImage *img = cvLoadImage(argv[1]);

    if(!img){
        printf("Could not load image file: %s\n",argv[1]);
        exit(0);
    }

	CvVideoWriter *writer = 0;
	int isColor = 1;
	int fps     = 25;  // or 30
	writer=cvCreateVideoWriter("out.avi",CV_FOURCC('P','I','M','1'),fps,cvSize(img->width, img->height),isColor);

	// Writing the video file:

	int nFrames = 50;
	for(int i=0;i<nFrames;i++){
	  //cvGrabFrame(capture);          // capture a frame
	  //img=cvRetrieveFrame(capture);  // retrieve the captured frame
	  cvWriteFrame(writer,img);      // add the frame to the file
	  cvShowImage("mainWin", img); 
	  key=cvWaitKey(20);           // wait 20 ms
	}

	// Show the final image
    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
	cvShowImage("mainWin", img );
	cvWaitKey(0);

	// clear the memory
	cvReleaseImage( &img );
    //cvReleaseVideoWriter( &videowriter );
    cvReleaseVideoWriter( &writer );
    return 0;
}
